﻿package game.account.shop {
	import flash.events.Event;
	import game.ui.Button;
	import game.ui.DynamicClip;
	import game.objects.DynamicObject;
	import flash.events.MouseEvent;
	import game.ui.Text;
	import game.objects.DonatObject;
	
	public class ShopDonat extends DynamicClip {
		
		
		
		private function get btnClose():Button	{ return getChildByName('btnClose')	as Button;	}
		private function get header():Text		{ return getChildByName('header')	as Text;	}
		
		public function ShopDonat():void {
			var skin:DynamicObject = config.getSkin(DynamicObject.SHOP_DONAT);
			
			super(skin);
			
			if (!skin) return;
			
			if (!btnClose || !header) return;
			
			header.set("IDS_DONAT_HEADER");
			btnClose.addEventListener(MouseEvent.CLICK, closeHandler);
			
			var Y:Number	= 55;
			var X:Number	= 22;
			var j:int		= 0;
			for each (var d:DonatObject in config.server.arrayDonat) {
				var item:ShopDonatItem = new ShopDonatItem (d);
				addChild(item);
				item.x = X;
				item.y = Y;
				
				Y+=item.height+9;
				
				j++;
				if (j==4) {
					Y = 55;
					X = 303;
				}
			}
			/*if (!slider || !btnShopLeft || !btnShopRight) return;
			*/
			
			
		}
		
		private function closeHandler(event:MouseEvent):void {
			animate('alpha', 1, 0, 0.3, remove);
		}
		
		private function remove(event):void {
			try {
				this.parent.removeChild(this);
			} catch (e:Error) {
				
			}
		}
		/*
		public function addItem(id:int, cost:Number):void {
			var item:ShopCarItem = new ShopCarItem(id, cost);
			item.addEventListener(MouseEvent.CLICK, selectItem);
			slider.add ( item );
		}
		
		private function selectItem(event:MouseEvent):void {
			this.dispatchEvent( new ShopCarEvent ( ShopCarEvent.SELECT, {id: (event.target as ShopCarItem).id} ) );
		}
		
		public function step(value:int):void {
			if (slider)
				slider.step(value);
		}*/
		
	}
	
}